package com.cug.campus_sh_market_server.entity.param

import com.cug.campus_sh_market_server.util.UnderlineWithHump
import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty

/**
 * @description 排序参数
 * @author sxt
 * @date 2022/4/25 20:50
 * @version 1.0
 */
@ApiModel(description = "排序通用参数")
class OrderParam(orderInfo: List<String>?) {

    /**
     * 排序信息
     */
    @Suppress("MemberVisibilityCanBePrivate")
    @ApiModelProperty(value = "排序信息(可传数组)")
    val orderInfo: List<String>?

    /**
     * 排序参考列
     */
    private val orderConditions: ArrayList<Pair<Boolean, String>> = ArrayList()

    init {
        this.orderInfo = orderInfo
        this.orderInfo?.forEach {
            val tag = it[0]
            val column = it.substring(1)
            if (tag == '-') {
                orderConditions.add(Pair(false, UnderlineWithHump.HumpToUnderline(column)))
            } else {
                orderConditions.add(Pair(true, UnderlineWithHump.HumpToUnderline(column)))
            }
        }
    }

    fun orderConditions(): ArrayList<Pair<Boolean, String>> {
        return this.orderConditions
    }
}
